**************************************************************
** title:		How Group Appeals Shape Candidate Support 	**
** purpose: 	replication Study 1							**
** date:		march 2025 									**
** machine:		macOS Sonoma 14.4							**
** software:	Stata 18.0 									**	
**************************************************************


* --------------
* preamble
* --------------

	** install packages (if note installed yet)
	*ssc install mplotoffset

	** set working directory first (modify to your directory)
	cd "~/dropbox/symbolic group appeals project/replication materials/data"

	** load dataset	
	use  "study1.dta", clear	
	
	** set working directory for saving tables and figures (modify to your directory)
	cd "~/dropbox/symbolic group appeals project/replication materials/tables and figures"
	
	** set style for graphs
	grstyle init
	grstyle set plain, nogrid noextend		
	

* ---------------------
* variable coding
* ---------------------

	gen labourcandidate=1 if vignette_2_party_treatment==1
	replace labourcandidate=0 if vignette_2_party_treatment==2
	
	gen sharedpartisan=0 if profile_partyid!=7 	// don't know
	replace sharedpartisan=1 if labourcandidate==1 & profile_partyid==2	// labour
	replace sharedpartisan=1 if labourcandidate==0 & profile_partyid==1	// conservative
	
	gen agegroup=1 if age>=18 & age <=24
	replace agegroup=2 if age>=25 & age<=34
	replace agegroup=3 if age>=35 & age<=44
	replace agegroup=4 if age>=45 & age<=54
	replace agegroup=5 if age>=55 & age<=64
	replace agegroup=6 if age>=65 & age!=.
	
	label define agegroupl 1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+"
	label value agegroup agegroupl

* --------------------------------	
* main results study 1, figure 1	
* --------------------------------	

	** figure 1 (a): CLASS VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo class: reg  Q15_s i.workingclass##i.classinfovscontrol i.vignette_2_gender_treatment i.labourcandidate, robust
	sum Q15_s if e(sample)==1		// standard deviation outcome for calculating std effect (reported in paper)
	margins, dydx(classinfovscontrol) at(workingclass=(0 1))
	mplotoffset,  offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(4) ysize(4) saving(figure1a.gph, replace)	
	
	** figure 1 (b): RURAL VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo rural: reg  Q15_s i.smalltown##i.ruralinfovscontrol i.vignette_2_gender_treatment i.labourcandidate, robust
	margins, dydx(ruralinfovscontrol) at(smalltown=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area/small town" 1 "Lives in rural area/small town") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(4) ysize(4) saving(figure1b.gph, replace)
	
	** figure 1 (c): LOW EDU VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo edu: reg  Q15_s i.nograduate##i.eduinfovscontrol i.vignette_2_gender_treatment i.labourcandidate, robust
	margins, dydx(eduinfovscontrol) at(nograduate=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "University graduate" 1 "No university graduate") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(4) ysize(4) saving(figure1c.gph, replace)	
	
	** figure 1 (d): YOUNG VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo young: reg  Q15_s i.young##i.younginfovscontrol i.vignette_2_gender_treatment i.labourcandidate, robust
	margins, dydx(younginfovscontrol) at(young=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not young" 1 "Young") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(4) ysize(4) saving(figure1d.gph, replace)		
	

* --------------------------------	
* appendix C, detailed estimates
* --------------------------------	
	
	esttab class rural edu young using study1fullresults.tex , b(3) se(3) nogap r2 replace
	
* ---------------------------------
* appendix D, detailed age effects
* ---------------------------------			

	eststo age: reg  Q15_s i.agegroup##i.younginfovscontrol i.vignette_2_gender_treatment i.vignette_2_party_treatment, robust
	margins, dydx(younginfovscontrol) at(agegroup=(1 2 3 4 5 6))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(6) ysize(4) saving(young-agegroups.gph, replace)		

	esttab age using appendixDtable.tex , b(3) se(3) nogap r2 
	
* ------------------------------------		
* appendix E, DV = vote likelihood 
* ------------------------------------		

	** CLASS VIGNETTE estimations and marginal effects plots, DV = vote choice
	eststo class: reg  Q16_s i.workingclass##i.classinfovscontrol i.vignette_2_gender_treatment i.vignette_2_party_treatment, robust
	margins, dydx(classinfovscontrol) at(workingclass=(0 1))
	mplotoffset,  offset(0.15) recast(scatter) recastci(rspike) xtitle("")  xlabel(0 "Not working class" 1 "Working class" , labsize(medium)) title("") ytitle("AME assignment to treatment", size(medium)) ylabel(-2(1)2, labsize(medium))  legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(class-vote.gph, replace)	
	
	** RURAL VIGNETTE estimations and marginal effects plots, DV = vote choice
	eststo rural: reg  Q16_s i.smalltown##i.ruralinfovscontrol i.vignette_2_gender_treatment i.vignette_2_party_treatment, robust
	margins, dydx(ruralinfovscontrol) at(smalltown=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area/small town" 1 "Lives in rural area/small town") title("") ytitle("AME assignment to treatment") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(rural-vote.gph, replace)
	
	** LOW EDU VIGNETTE estimations and marginal effects plots, DV = vote choice
	eststo edu: reg  Q16_s i.nograduate##i.eduinfovscontrol i.vignette_2_gender_treatment i.vignette_2_party_treatment, robust
	margins, dydx(eduinfovscontrol) at(nograduate=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "At school after 20" 1 "Left school before 20") title("") ytitle("AME assignment to treatment") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(edu-vote.gph, replace)	
	
	** YOUNG VIGNETTE estimations and marginal effects plots, DV = vote choice
	eststo young: reg  Q16_s i.young##i.younginfovscontrol i.vignette_2_gender_treatment i.vignette_2_party_treatment, robust
	margins, dydx(younginfovscontrol) at(young=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "35+ years" 1 "Younger than 35") title("") ytitle("AME assignment to treatment") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(young-vote.gph, replace)

	** table
	esttab class rural edu young using appendixEtable.tex , b(3) se(3) nogap r2 
		
* ---------------------------------
* appendix F, effect by party
* ---------------------------------	

	** CLASS VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo class: reg  Q15_s i.vignette_2_party_treatment##i.workingclass##i.classinfovscontrol i.vignette_2_gender_treatment , robust
	margins, dydx(classinfovscontrol) at(workingclass=(0 1) vignette_2_party_treatment=(1 2))
	mplotoffset,  offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to treatment") ylabel(-2(2)4) legend( nobox cols(2) position(6) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(class-party.gph, replace)	
	
	** RURAL VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo rural: reg  Q15_s i.vignette_2_party_treatment##i.smalltown##i.ruralinfovscontrol i.vignette_2_gender_treatment , robust
	margins, dydx(ruralinfovscontrol) at(smalltown=(0 1) vignette_2_party_treatment=(1 2))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area/small town" 1 "Lives in rural area/small town") title("") ytitle("AME assignment to treatment") ylabel(-2(2)4) legend( nobox cols(2) position(6) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(rural-party.gph, replace)
	
	** LOW EDU VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo edu: reg  Q15_s i.vignette_2_party_treatment##i.nograduate##i.eduinfovscontrol i.vignette_2_gender_treatment , robust
	margins, dydx(eduinfovscontrol) at(nograduate=(0 1) vignette_2_party_treatment=(1 2))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "At school after 20" 1 "Left school before 20") title("") ytitle("AME assignment to treatment") ylabel(-2(2)4) legend( nobox cols(2) position(6) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(edu-party.gph, replace)	
	
	** YOUNG VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo young: reg  Q15_s i.vignette_2_party_treatment##i.young##i.younginfovscontrol i.vignette_2_gender_treatment , robust
	margins, dydx(younginfovscontrol) at(young=(0 1) vignette_2_party_treatment=(1 2))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "35+ years" 1 "Younger than 35") title("") ytitle("AME assignment to treatment") ylabel(-2(2)4) legend( nobox cols(2) position(6) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5)  saving(young-party.gph, replace)	
	
	** table
	esttab class rural edu young using appendixFtable.tex , b(3) se(3) nogap r2 
		
* --------------------------------------------
* appendix P, shared partisanship (study 1)
* --------------------------------------------
	
	** CLASS VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo class: reg  Q15_s i.workingclass##i.classinfovscontrol i.vignette_2_gender_treatment i.sharedpartisan, robust
	margins, dydx(classinfovscontrol) at(workingclass=(0 1))
	mplotoffset,  offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(class-main-shared.gph, replace)	
	
	** RURAL VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo rural: reg  Q15_s i.smalltown##i.ruralinfovscontrol i.vignette_2_gender_treatment i.sharedpartisan, robust
	margins, dydx(ruralinfovscontrol) at(smalltown=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area/small town" 1 "Lives in rural area/small town") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(rural-main-shared.gph, replace)
	
	** LOW EDU VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo edu: reg  Q15_s i.nograduate##i.eduinfovscontrol i.vignette_2_gender_treatment i.sharedpartisan, robust
	margins, dydx(eduinfovscontrol) at(nograduate=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "At school after 20" 1 "Left school before 20") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(edu-main-shared.gph, replace)	
	
	** YOUNG VIGNETTE estimations and marginal effects plots, DV = candidate rating
	eststo young: reg  Q15_s i.young##i.younginfovscontrol i.vignette_2_gender_treatment i.sharedpartisan, robust
	margins, dydx(younginfovscontrol) at(young=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "35+ years" 1 "Younger than 35") title("") ytitle("AME assignment to treatment") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) xsize(3.5) ysize(2) scale(1.5) saving(young-main-shared.gph, replace)		
	
	** table
	esttab class rural edu young using appendixPtable1.tex , b(3) se(3) nogap r2 
	
	
	
	
	
	
	